<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "grp_class".
 *
 * @property integer $id
 * @property string $name
 * @property integer $father
 */
class GrpClass extends \yii\db\ActiveRecord
{
    public $imgurl;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'grp_class';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['id', 'father'], 'integer'],
            [['name'], 'string', 'max' => 24]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => Yii::t('app','Class Name'),
            'father' => '上级分类',
            'img_id'=>'图片'
            
        ];
    }
	    /**
     * 
     * @param unknown $id
     * @return Ambigous <\yii\db\static, NULL, multitype:, boolean, \yii\db\ActiveRecord>
     */
    public static function find_class_name($id){
    	return self::findOne(['id' => $id])['name'];
    }

    public static function class1()
    {
        return self::find()->where(['father'=>0])->asArray()->all();
    }
    public static function class2($class1_id)
    {
        return self::find()->where(['father'=>$class1_id])->asArray()->all();
    }
    public static function class3($class2_id)
    {
        return self::find()->where(['father'=>$class2_id])->asArray()->all();
    }
    public function search($params)
    {
        $query=GrpClass::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination'=>['pageSize' => '10'],
        ]);
        
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        return $dataProvider;
    }
}
